package com.it.schoolbookshop_back.enums;

/**
 * 书籍状态枚举
 */
public enum BookStatusEnum {
    ACTIVE("active", "在售中"),
    RESERVED("reserved", "已预约"),
    SOLD("sold", "已售出"),
    REMOVED("removed", "已下架");

    private final String value;
    private final String label;

    BookStatusEnum(String value, String label) {
        this.value = value;
        this.label = label;
    }

    public String getValue() {
        return value;
    }

    public String getLabel() {
        return label;
    }

    /**
     * 根据状态值获取枚举
     * @param value 状态值
     * @return 枚举实例，如果未找到返回null
     */
    public static BookStatusEnum fromValue(String value) {
        for (BookStatusEnum status : BookStatusEnum.values()) {
            if (status.getValue().equals(value)) {
                return status;
            }
        }
        return null;
    }
    
    /**
     * 检查状态值是否有效
     * @param value 状态值
     * @return 是否有效
     */
    public static boolean isValid(String value) {
        return fromValue(value) != null;
    }
} 